package com.jsbs.iam.user.controller;

import com.jsbs.iam.common.core.dto.Result;
import com.jsbs.iam.common.core.utils.StringUtils;
import com.jsbs.iam.user.service.AdminRoleService;
import com.jsbs.iam.user.vo.AdminRoleVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @BelongsProject: iam
 * @BelongsPackage: com.jsbs.iam.user.controller
 * @Author: WangJiYuan
 * @Description: 权限获取
 * @Version: 2023-01-18  10:34
 */
@RestController
@RequestMapping("/iam/user/adminRole")
public class AdminRoleController extends BaseController {

    private static final Logger logger = LoggerFactory.getLogger(AdminRoleController.class);

    @Autowired
    private AdminRoleService adminRoleService;

    /**
     * 查询管理员权限列表
     * @param roleCode  角色编码
     * @param companyCode  租户编码
     * @return
     */
    @PostMapping("/queryAdminRole")
    public Result queryAdminRole(@RequestParam("roleCode") String roleCode,@RequestParam("companyCode") String companyCode) {
        logger.info("Route==>AdminRoleController method=queryAdminRole 查询管理员权限列表，入参：{}", "<userCode:"+roleCode+"><companyCode:"+companyCode+">");
        try {
            if (StringUtils.isEmpty(companyCode)) {
                logger.warn("Route=>AdminRoleController method=>queryAdminRole 查询管理员权限列表，归属租户信息异常");
                return Result.failWithMsg("归属租户信息异常");
            }
            if (StringUtils.isEmpty(roleCode)) {
                logger.warn("Route=>AdminRoleController method=>queryAdminRole 查询管理员权限列表，登录人角色信息异常");
                return Result.failWithMsg("登录人角色信息异常");
            }
            //查询管理员权限列表
            AdminRoleVo adminRoleVo = adminRoleService.queryAdminRole(roleCode, companyCode);
            return Result.success("查询管理员权限列表成功", adminRoleVo);
        } catch (Exception e) {
            logger.error("Route==>AdminRoleController method=queryAdminRole 查询管理员权限列表异常：{}，入参：{}", e, "<userCode:"+roleCode+"><companyCode:"+companyCode+">");
            return handleException(e);
        }
    }

}

